package src

import (
	"fmt"
	"strconv"
	"sync"
	"time"
)

package main

import (
"fmt"
"strconv"
"sync"
"time"
)

func main() {
	// 有一串字符串，由字母和数字组成，要求数字和字母交替打印
	// 如：12ab2Ac3G14567，输出  1a2b2A3c1G4567
	// 要求golang实现，并用到goroutine、channel等技术

	//字符串的chan
	str := make(chan string)
	//数字的chan
	num := make(chan int)

	// := make(chan string)
	//数字的chan
	//num := make(chan int)
	//如果为空 需要关掉go 和 chan 要不会泄漏
	defer  close(str)
	defer  close(num)

	defer  func(){
		fmt.Printf("\n ssdfsdf \n")
	}()

	s := "12d123ds9fg45a"
	strstr, strint := []string{}, []int{}
	for _, v :=  range s {
		if v <= 59 {
			i ,_  := strconv.Atoi( string(v))
			strint = append(strint, i)
		}else{
			strstr = append(strstr, string(v))
		}
	}
	fmt.Printf("\n strstr %+v strint %+v \n",strstr, strint)

	l := len(strint) + len(strstr)
	go func(strstr []string, l int){
		for i:=0; i < l; i++ {
			<-str
			if len(strstr) > i {
				fmt.Printf(strstr[i])
			}
			num <- 1
		}
	}(strstr, l)

	go func(strint []int, l int) {

		for i:=0; i < l; i++ {
			<-num
			if len(strint)  > i {
				fmt.Printf("%d", strint[i])
			}
			str <- "1"
		}
	}(strint, l)

	num <- 1
	time.Sleep(1 * time.Second)
	return
}
